import { network } from "../../utils/network.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 18886,
    allid:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    wx.showLoading({
      title: '加载中...',
    })

    var that=this
    that.setData({
      id:options.id
    })
    wx.request({
      url: 'https://api.imjad.cn/cloudmusic/?type=playlist',
      data:{
        id:options.id
      },
      success: function (res) {
        that.setData({
          playlist:res.data.playlist,
          songsid: res.data.playlist.trackIds
        })
        console.log(res.data.playlist)
        console.log(res.data.playlist.trackIds)

        var songsid = res.data.playlist.trackIds
        var songs = []
        for (var index = 0; index < songsid.length && index < 50 ; index++) {
          var savedid = songsid[index].id;
          network.getDetail({
            id: savedid,
            success: function (song) {
              songs.push(song)
              that.setData({
                songs: songs,
              })
            }
          })
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.hideLoading()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onAllplayEvent:function(){
    var ids=[]
    for (var i = 0; i < this.data.songs.length;i++ ){
      ids.push({id:this.data.songs[i].id})
      this.setData({
        ids: ids
      })
    }
    getApp().globalData.playing=ids;
    getApp().globalData.playno = 0
    console.log(getApp().globalData.playing)
    wx.navigateTo({
      url: '../detail/detail?id=' + ids[0].id + '&playnow=true',
    })
  }
})